<%@ include file="/common/taglibs.jsp"%>


<head>
    <title><fmt:message key="codex.municipality"/></title>
    <meta name="heading" content="<fmt:message key='codex.municipality'/>"/>
    <meta name="menu" content="CodexMenu"/>
</head>

<div class="jquery_tab_container">
    <span class="heading_tab advanced_link active tab1"><fmt:message key="codex.municipality"/></span>
</div>

<div class="jquery_tab">
    <div class="content_block"></div>
<form:form commandName="municipality" method="post" action="municipalityform" id="municipalityForm" onsubmit="return validateMunicipality(this)">
<form:errors path="*" cssClass="error" element="div"/>
<form:hidden path="id"/>
 
    <p>
        <appfuse:label styleClass="left width50" key="field.name"/>
        <form:input path="name" id="name" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error" maxlength="1000"/>
        <form:errors path="name" cssClass="fieldError left"/>
        <br class="clearboth" />
    </p>

    <p>
        <appfuse:label styleClass="left width50" key="user.address.country"/>
        <form:input id="country" path="country.name" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error" maxlength="1000"/>
        <form:hidden id="countryId" path="country.id" cssClass="fieldError left"/>
        <br class="clearboth" />
    </p>

    <p>
        <appfuse:label styleClass="left width50" key="field.code"/>
        <form:input path="code" id="code" cssClass="input-medium left" cssErrorClass="input-medium left error" maxlength="50"/>
        <form:errors path="code" cssClass="fieldError left"/>
        <br class="clearboth" />
    </p>
    <p>
        <appfuse:label styleClass="left width50" key="field.description"/>
        <form:textarea path="descr" id="descr" cssClass="input-medium left" cssErrorClass="input-medium left error" maxlength="4096"/>
        <form:errors path="descr" cssClass="fieldError left"/>
        <br class="clearboth" />
    </p>
     <p>
            <appfuse:label styleClass="left width50" key="status.active"/>
            <form:checkbox path="status" value="1" id="status"  cssClass="input-medium left" cssErrorClass="input-medium left error"  />
            <form:errors path="status" cssClass="fieldError left"/>
            <br class="clearboth" />
        </p>

    <p class="buttonBar bottom">
        <input type="submit" class="button" name="save" value="<fmt:message key="button.save"/>"/>
        <%--<c:if test="${not empty municipality.id}">
        <input type="submit" class="button" name="delete" onclick="bCancel=true;return confirmDelete('municipality')"
            value="<fmt:message key="button.delete"/>" />
        </c:if>--%>
        <input type="submit" class="button" name="cancel" value="<fmt:message key="button.cancel"/>" onclick="bCancel=true"/>
    </p>

</form:form>
</div>
<v:javascript formName="municipality" cdata="false" dynamicJavascript="true" staticJavascript="false"/>
<script type="text/javascript" src="<c:url value='/scripts/validator.jsp'/>"></script>

<script type="text/javascript">
    Form.focusFirstElement($('municipalityForm'));
</script>
 <script type="text/javascript">
 new Autocomplete('country', {
    serviceUrl:'<c:url value="/hello.json" />',
    minChars:2,
    clazz: "Country",
    parent: "",
    maxHeight:500,
    width:300,
    deferRequestBy:300,
    // callback function:
    onSelect: function(value, data){
        jQuery("#countryId").val(data);
    }
  });

  jQuery("#country").blur( function () {
            if (jQuery("#countryId").val() == "") {
                jQuery(this).val("");
            }
            if (jQuery(this).val() == "") {
                jQuery("#countryId").val();
            }

  });
</script>